﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EulerNo3
{
    class Program
    {
        static void Main(string[] args)
        {
            //euler project 3
            //What is the largest prime factor of the number 600851475143 ?

            long number = 600851475143;
            long maxPrimeFactor = 0;

            for (long i = 1; i <= number / 2; i++)
            {
                double valdouble = Convert.ToDouble(number)/ i;
                long vallong = number / i;

                if (vallong ==valdouble){
                    if (checkPrime(i))
                        Console.WriteLine("Prime Found: " + i.ToString());
                        maxPrimeFactor = i;
                }
            }
            Console.Beep();
            Console.WriteLine("Max Prime Factor of " + number.ToString() + ": " + maxPrimeFactor.ToString());
            Console.Read();
        }

        private static bool checkPrime(long val)
        {
            if (val > 0)
            {
                for (long i = 2; i < val; i+=2)
                {
                    long results = val % i;
                    if (results == 0)
                        return false;
                }
                return true;
            }
            else 
                return false;
        }
    }
}
